Skip to content

Add prompt-gateway: MCP-based task contract compiler and agent router#3

Open
DataDanAi wants to merge 4 commits intoRangizingo:mainfrom
DataDanAi:claude/prompt-compiler-mcp-msXOk
Open

Add prompt-gateway: MCP-based task contract compiler and agent router#3
DataDanAi wants to merge 4 commits intoRangizingo:mainfrom
DataDanAi:claude/prompt-compiler-mcp-msXOk

Conversation

@DataDanAi
Copy link
Copy Markdown

Summary

This PR introduces prompt-gateway, a new system that compiles raw human intent into structured task contracts and routes them to appropriate execution surfaces. It provides a unified interface for multiple clients (Cursor, CLI, desktop, local agents, APIs) through both MCP (Model Context Protocol) and HTTP servers.

Key Changes

Core Architecture

  • Task Contract System (src/types.ts): Canonical schema for representing compiled tasks with intent, constraints, risk assessment, execution mode, and validation criteria
  • Compiler Pipeline (src/compiler/): Multi-stage compilation from raw input to structured contracts:
    • Intent classification (task type detection)
    • Constraint extraction (parsing requirements and limitations)
    • Context selection (anti-stuffing: only relevant workspace context)
    • Risk assessment and execution mode selection
    • Tool resolution and validation check generation

Server Implementations

  • MCP Server (src/mcp/server.ts): Exposes gateway as MCP tools for Cursor, Claude, and other MCP-compatible clients with operations: compile, evaluate, route, approve, validate, get-run
  • HTTP Server (src/server/http.ts): REST API endpoints for compile, execute, approve, and run management
  • CLI Agent (src/bin/agent.ts): Command-line entry point with human-readable and JSON output modes

Policy & Routing

  • Policy Engine (src/policy/engine.ts): Rule-based evaluation of compiled contracts (approval requirements, surface permissions, risk gates)
  • Router (src/router/index.ts): Intelligent routing logic that maps task types to execution surfaces (Cursor for code editing, CLI for shell work, desktop for design specs, etc.)

Storage & Validation

  • SQLite Storage (src/storage/db.ts): Persistent run tracking, approvals, memory, policies, and logs with WAL mode
  • Validator (src/validator/index.ts): Post-execution validation against contract criteria (compilation checks, test passes, exit codes, deployment health)

Input Adapters

  • CLI Adapter (src/adapters/cli.ts): Captures working directory, git state, environment
  • Cursor Adapter (src/adapters/cursor.ts): IDE-specific metadata extraction
  • Desktop Adapter (src/adapters/desktop.ts): UI surface transport layer
  • Local Agent Adapter (src/adapters/local-agent.ts): Agent-to-gateway communication

Notable Implementation Details

  • Anti-stuffing context selection: Tasks only receive relevant workspace context based on type and mentioned files, not entire workspace dumps
  • Risk-driven execution modes: High-risk tasks default to "plan_then_act" with approval gates; low-risk queries use lightweight "think" mode
  • Unified contract format: All surfaces (Cursor, CLI, desktop, agents) consume the same TaskContract schema, ensuring consistent behavior
  • Extensible policy rules: Policy engine supports custom rules beyond built-in high-risk and deploy-surface checks
  • Validation checks: Post-execution validation includes compilation checks, test results, lint errors, exit codes, and deployment health
  • Dual server architecture: MCP stdio for IDE integration + HTTP for CLI/desktop/API clients running simultaneously

Configuration

  • Default HTTP port: 4840
  • Database location: .prompt-gateway/gateway.db
  • Supports --http and --mcp flags to run servers independently

https://claude.ai/code/session_01WvBZW9gNfJSXGnCF6UGakJ

claude added 4 commits April 2, 2026 02:48
Implements a full prompt compilation pipeline that converts raw human
input into structured task contracts, with MCP as the backbone for
cross-surface interoperability (CLI, Cursor/IDE, desktop, local agents).

Architecture:
- Compiler: classifier, constraint extractor, context selector, contract builder
- Policy engine: risk assessment, approval gates, tool scope guards
- Runtime router: routes tasks to optimal execution surface
- Validator: checks execution results against contract criteria
- Storage: SQLite for runs, approvals, memory, policies, structured logs
- MCP server: exposes all gateway capabilities as MCP tools/resources/prompts
- HTTP server: REST endpoints (compile, execute, approve, validate, runs)
- Input adapters: CLI, Cursor, desktop, local-agent
- CLI entry point: `agent "fix the auth race and keep changes minimal"`

https://claude.ai/code/session_01WvBZW9gNfJSXGnCF6UGakJ
- esbuild bundles CLI and daemon into single .mjs files (149K + 1.9M)
- setup.sh: one-command install (npm install + build + PATH shims)
- `agent "your prompt"` CLI command via bin shim
- `prompt-gateway --mcp-config` prints Cursor/Claude/Claude Code config
- `prompt-gateway --http` starts REST daemon on port 4840
- `prompt-gateway --mcp` starts MCP stdio server

https://claude.ai/code/session_01WvBZW9gNfJSXGnCF6UGakJ
setup.sh and setup.ps1 now automatically:
- Build the bundles
- Create CLI shims (agent, prompt-gateway)
- Auto-detect and configure Cursor, Claude Desktop, Claude Code,
  VS Code, and Windsurf MCP configs (merges without clobbering)
- Add bin/ to PATH (bashrc/zshrc on Linux, user PATH on Windows)

One command to install: `bash setup.sh` or `.\setup.ps1`

https://claude.ai/code/session_01WvBZW9gNfJSXGnCF6UGakJ
Windows (setup.ps1 + setup.bat):
- setup.bat for double-click install (bypasses execution policy)
- Forward-slash paths in JSON configs (fixes backslash escaping)
- PowerShell shims alongside .cmd shims
- Graceful error handling for unparseable config files
- JetBrains IDE auto-detection and config
- Quick self-test after build
- Pause-on-error when launched via double-click

Linux (setup.sh):
- Fix stdout leaking from node merge scripts
- Add Windsurf and JetBrains auto-detection
- Add quick self-test after build

https://claude.ai/code/session_01WvBZW9gNfJSXGnCF6UGakJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants